import {Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToMany, JoinTable} from 'typeorm'
import { Permission } from './permission.entity';

@Entity({
    name: 'user'
})
export class User {
    @PrimaryGeneratedColumn({
        comment: '索引id'
    })
    id: number

    @Column({
        comment: '用户名称',
        length: 50,
    })
    username: string

    @Column({
        comment: '用户密码',
        length: 50,
    })
    password: string

    @CreateDateColumn({
        comment: '创建时间'
    })
    createTime: Date;

    @UpdateDateColumn({
        comment: '更新时间'
    })
    updateTime: Date;

    // user表和permission 表建立多对多的关系
    @ManyToMany(() => Permission)
    @JoinTable({
        name: 'user_permission_relation'
    })
    permissions: Permission[] 

}
